package com.vtb.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import weibo4j.Oauth;
import weibo4j.model.WeiboException;

import com.vtb.base.VtbBaseServlet;

/**
 * 新浪微博授权连接
 * @author Chen Tao
 * @date 2012-7-9 下午3:16:35
 */
@SuppressWarnings("serial")
public class SsConnServlet extends VtbBaseServlet{
    private static final Log log = LogFactory.getLog(SsConnServlet.class);
    Oauth oauth = new Oauth();
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            String authorize = oauth.authorize("code");
            response.sendRedirect(authorize);
        } catch (WeiboException e) {
            log.error("获取新浪code失败：", e);
            response.sendRedirect("error?err_code=1002");
            throw new WtbException("获取新浪code失败"+e);
        }
    }
    
}
